

class AbstractStack {
    randerView(){
    }
}
class HashStack extends AbstractStack{
    setData(data){
        this.data = data
    }
    randerView(){
        //复用页面
        console.log("渲染页面",this.data)
    }
}

//浏览页面
const stackList = ["detail","list","holdDetail","result","buy"]
const map = new Map()
function getStackFactory(hash){
    if(!map.get(hash)){
        const hashStack = new HashStack()
        map.set(hash,hashStack)
    }
    return map.get(hash)
}

function test(){
    for (let i = 0; i <= 20; i++) {
        const hash = stackList[parseInt(stackList.length*Math.random())]
        const stack = getStackFactory(hash)
        stack.setData(hash+"数据"+i)
        stack.randerView()
    }
    console.log(map.size+":size")
}
test()


